package com.gopay.checkorder.service.task;

import java.util.ArrayList;
import java.util.List;

public class BankCountDownLatch {

	private static final List<String> bankCountDownLatch = new ArrayList<String>();

	private static final List<String> bankCountDownLatchFail = new ArrayList<String>();
//	private static final Map<String, Integer> bankCountDownLatch = new HashMap<String, Integer>();
//	
//	private static final Map<String, Integer> bankCountDownLatchFail = new HashMap<String, Integer>();

//	private final ReentrantLock takeLock = new ReentrantLock();
//	
//	private final ReentrantLock failTakeLock = new ReentrantLock();

	public static void totalIncrease(String bankName) {
		
		bankCountDownLatch.add(bankName);
/*
		final ReentrantLock takeLock = this.takeLock;

		takeLock.lock();
		try {
			if(bankCountDownLatch.containsKey(bankName)){
				Integer latch = bankCountDownLatch.get(bankName);
				latch ++ ;
				bankCountDownLatch.remove(bankName);
				bankCountDownLatch.put(bankName, latch);
			}else{
				bankCountDownLatch.put(bankName, 1);
			}
		} finally {
			takeLock.unlock();
		}*/

	}

	public static void failIncrease(String bankName) {
		
		bankCountDownLatchFail.add(bankName);
		/*final ReentrantLock takeLock = this.failTakeLock;

		takeLock.lock();
		try {
			if(bankCountDownLatchFail.containsKey(bankName)){
				Integer latch = bankCountDownLatchFail.get(bankName);
				latch ++ ;
				bankCountDownLatchFail.remove(bankName);
				bankCountDownLatchFail.put(bankName, latch);
			}else{
				bankCountDownLatchFail.put(bankName, 1);
			}
		} finally {
			takeLock.unlock();
		}*/
	}
	
	public static void clearBankCountDownLatch(){
		
		bankCountDownLatch.clear();
	}
	
	public static void clearBankCountDownLatchFail(){
		bankCountDownLatchFail.clear();
	}
	
	public static List<String> getBankCountDownLatch(){
		return bankCountDownLatch;
	}
	public static List<String> getBankCountDownLatchFail(){
		return bankCountDownLatchFail;
	}
	
}
